package com.person.jc.service.frame;

import java.util.ArrayList;
import java.util.List;

import com.jfinal.plugin.activerecord.Record;


public class FrameService {
	
	public static final FrameService me = new FrameService();
	
	public String getSubMenuDiv(List<Record> menuList,String menuId){
		 List<Record> secondMenu = new ArrayList<Record>();
		 List<Record> thirdMenu = new ArrayList<Record>();
		 for (Record obj : menuList) {
			if(String.valueOf(obj.getStr("menu_id")).startsWith(menuId) && "2".equals(String.valueOf(obj.getInt("menu_lvl")))){
				secondMenu.add(obj);
			}else if(String.valueOf(obj.getStr("menu_id")).startsWith(menuId) && "3".equals(String.valueOf(obj.getInt("menu_lvl")))){
				thirdMenu.add(obj);
			}
		}
		StringBuffer menuDiv = new StringBuffer();
		for (Record smenu : secondMenu) {
			String sMenuId = String.valueOf(smenu.get("menu_id"));
			menuDiv.append("<div  class=\"nav1\">");
			menuDiv.append("<div  class=\"nav1Title\">");
			menuDiv.append("<p class=\"nav1p\">"+smenu.get("menu_name")+"</p>");
			menuDiv.append("<div class=\"triangle\">");
			menuDiv.append("<div class=\"triangle-right\"></div>");
			menuDiv.append("</div>");
			menuDiv.append("</div>");
			menuDiv.append("<div class=\"nav2\">");
			menuDiv.append("<ul>");
			for (Record tmenu : thirdMenu) {
				if(String.valueOf(tmenu.get("menu_id")).startsWith(sMenuId)){
					menuDiv.append("<li title=\""+tmenu.get("menu_name")+"\" menuId=\""+tmenu.get("menu_id")+"\" url=\""+tmenu.get("url")+"\"><p>"+tmenu.get("menu_name")+"</p></li>");
				}
			}
			menuDiv.append("");
			menuDiv.append("</ul>");
			menuDiv.append("</div>");
			menuDiv.append("</div>");
		}
		return menuDiv.toString();
	 }
}
